#include<bits/stdc++.h>
#define N 5000005
#define M 998244353
using namespace std;
int f[N],can[1005][1005],n,po[N][2];
bool vs[22][1<<20],ct[22][1<<20]; char s[N];
int h[22][1<<20];
void inc(int &x,int y){x+=y; if(x>=M) x-=M;}
void DP(){
	for(int i=1;i<=n+1;i++) can[i][i-1]=1;
		for(int ln=2;ln<=n;ln+=2) for(int l=1;l+ln-1<=n;l++){
			int r=l+ln-1;
			for(int k=l;k<r;k++) can[l][r]|=(can[l][k]&can[k+1][r]);
			if(!(s[l]=='A'&&s[r]=='B')) can[l][r]|=can[l+1][r-1];
		}
	for(int i=1;i<=n;i++){
		for(int r=1;r<=i;r++){ bool fl=1;
			for(int j=r;j<i;j++) if(can[r][j-1]&&s[j]==s[i])
				fl=0; 
			if(!fl) continue; 
			if(can[r][i-1]) inc(f[i],f[r-1]);
			else{ fl=0;
				for(int j=r;j<i;j++) if(can[r-1][j-1]&&can[j+1][i-1]&&s[j]==s[r-1])
					fl=1;
				if(fl) inc(f[i],f[r-1]);
			}
		}
	}int ans=0;
	for(int i=0;i<=n;i++) if(can[i+1][n]) inc(ans,f[i]);
	printf("%d\n",ans);
}void dfs(int msk,int n0){
	if(!n0){h[n0][msk]=1; return;}
	if(n0==1){h[n0][msk]=1; return;}
	if(vs[n0][msk]) return; vs[n0][msk]=1;
	h[n0][msk]=1;
	for(int i=0;i<n0-1;i++)
		if(!((msk>>i&1)==0&&(msk>>(i+1)&1)==1)){
			int m0=((msk&((1<<i)-1))|((msk>>(i+2))<<i));
			dfs(m0,n0-2);
		}
}signed main(){
	freopen("song.in","r",stdin);
	freopen("song.out","w",stdout);
	scanf("%s",s+1),n=strlen(s+1),f[0]=1;
	if(n<=20){ int ans=0,m1=0;
		for(int i=0;i<n;i++) m1|=(1<<i)*(s[i+1]-'A');
		h[0][0]=1; dfs(m1,n); 
		for(int S=0;S<(1<<n);S++){ int ln=0,msk=0;
			for(int i=n-1;~i;i--) if(S>>i&1)
				msk=((msk<<1)|(s[i+1]-'A')),ln++;
			if(h[ln][msk]){
				if(!ct[ln][msk]) ++ans;
				ct[ln][msk]=1; }
		}return !printf("%d\n",ans);
	}else printf("%d\n",(n+1)/2+1);
	return 0;
}
